package com.rj.bd.sys.filters;

/**
 * @desc 打印请求参数过滤器
 * @author 白世俊
 * @datetime: 2024-12-26 11:00
 */
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebFilter("/*")
public class PrintAllArgsFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
        Map<String, String[]> parameterMap = req.getParameterMap();
        System.out.println("**************本次请求参数如下***************");
        for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
            String parameterName = entry.getKey();
            String[] parameterValues = entry.getValue();
            System.out.print("参数名: " + parameterName);
            if (parameterValues!= null) {
                for (String value : parameterValues) {
                    System.out.println("\t参数值: " + value);
                }
            }
        }
        System.out.println("\n*******************************************");
        chain.doFilter(req, res);
    }
}
